<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>图书馆里</title>

    <link rel="stylesheet" href="/static/css/hui.css">

</head>

<body>
    <header class="hui-header">
        <h1>管理员-图书管理</h1>
    </header>
    <div class="hui-wrap" style="padding-bottom: 40px">
        <div class="hui-refresh-content hui-list" id="list">
            {% for book in books %}
            <div class="hui-swipe-do">
                <div class="hui-swipe-do-doms hui-list-text" style="width: 555px;">

                    <div class="hui-swipe-do-content" style="width: 415px;">
                        <div style="line-height:30px; padding:10px 8px;">
                            <p>{{book.bookName}}
                                <span style="display: none">{{book.bookID}}</span>
                            </p>
                        </div>
                    </div>
                    <div class="hui-swipe-do-btn hui-swipe-do-btn-gray" onclick="bookDetails(this);" style="height: 50px; line-height: 50px;">详情</div>
                    <div class="hui-swipe-do-btn" onclick="removeDom(this);" style="height: 50px; line-height: 50px;">删除</div>
                </div>
            </div>
            {% endfor %}
        </div>


    </div>
    <a href="/addBook/" class="hui-button hui-button-large hui-primary" style="position: fixed;bottom: 0">添加图书</a>


    <script type="text/javascript" src="/static/js/jquery-2.1.4.js"></script>
    <script type="text/javascript" src="/static/js/hui.js"></script>
    <script src="/static/js/hui-refresh-load-more.js"></script>
    <script>

        //初始化
        hui.swipeDo();

        //书本详情
        function bookDetails(cdom) {
            var bookId = $(cdom).siblings().find('span').text();

            hui.open('http://127.0.0.1:5000/bookDetails/' + bookId);

        }

        //删除功能
        function removeDom(cdom) {
            var bookId = $(cdom).siblings().find('span').text();


            hui.confirm('删除书本ID：' + bookId, ['取消', '确定'], function () {
                $.ajax({
                    url: 'http://127.0.0.1:5000/adminDeleteBook/',
                    type: 'POST',
                    cache: false,
                    dataType: 'json',
                    data: { bookId: bookId },
                    success: (data) => {
                        console.log(data.message)
                        var dDom = hui(cdom).parent().parent();
                        dDom.hide(true);
                        setTimeout(function () { dDom.remove(); }, 300);
                    }
                })
            });




        }




    </script>
</body>

</html>